using System;
using UnityEngine;

[Serializable]
public class ABTestElement
{
	public bool initialized;

	public string key = string.Empty;

	public string useForVersion = string.Empty;

	public int serverProbability;

	public int resultProbability = -1;

	public ABTestElement(string key, int serverProbability, string useForVersion = "")
	{
		if (!string.IsNullOrEmpty(key))
		{
			Init(key, serverProbability, useForVersion);
		}
	}

	public void Init(string key, int serverProbability, string useForVersion)
	{
		this.key = key;
		this.serverProbability = serverProbability;
		this.useForVersion = useForVersion;
		initialized = BCWStorage.Get<bool>(key + "_initialized");
		if (initialized)
		{
			resultProbability = BCWStorage.Get<int>(key + "_resultProbability");
			return;
		}
		resultProbability = SetResultProbability();
		BCWStorage.Set(key + "_initialized", true, true);
		initialized = true;
	}

	public bool IsActive()
	{
		if (initialized && useForVersion != string.Empty)
		{
			string[] array = useForVersion.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == BuildNumberForInapps.BuildNumber && serverProbability > 0)
				{
					return resultProbability <= serverProbability;
				}
			}
			return false;
		}
		if (serverProbability > 0 && initialized && resultProbability >= 0)
		{
			return resultProbability <= serverProbability;
		}
		return false;
	}

	private int SetResultProbability()
	{
		int num = (resultProbability = UnityEngine.Random.Range(0, 100));
		BCWStorage.Set(key + "_resultProbability", num, true);
		return num;
	}
}
